package com.wy.controller.wy;

import com.wy.model.sys.Cars;
import com.wy.model.sys.PageResult;
import com.wy.service.wy.CarsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/cars")
public class CarsController {
    private Logger logger = LoggerFactory.getLogger(CarsController.class);

    @Resource(name = "carsServiceImpl")
    private CarsService carsService;

    /**
     * 获取车辆列表数据
     *
     * @param pageSize
     * @param page
     * @param plateNum 车牌号码
     * @param householdName 业主姓名
     * @return
     */
    @GetMapping("")
    @ApiOperation(value="carList",notes="")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = false,dataType = "Int", paramType = "query", defaultValue = "10"),
            @ApiImplicitParam(name = "page", value = "当前页数", required = false,dataType = "Int", paramType = "query",defaultValue = "1"),
            @ApiImplicitParam(name = "plateNum", value = "车牌号码", required = false,dataType = "String", paramType = "query",defaultValue = ""),
            @ApiImplicitParam(name = "householdName", value = "业主姓名", required = false,dataType = "String", paramType = "query",defaultValue = ""),
    })
    public PageResult carList(int pageSize, int page, String plateNum, String householdName) {
        PageResult pageResult = new PageResult();
        pageResult.setData(carsService.carList(pageSize, page * pageSize,plateNum,householdName));
        pageResult.setTotalCount(carsService.carSize(pageSize,  page * pageSize,plateNum,householdName));
        logger.debug("The method is ending");
        return pageResult;
    }

    /**
     * 添加车辆信息
     * @param cars
     * @return
     */
    @PostMapping("")
    public Cars insertCars(@RequestBody Cars cars){
        carsService.insertCar(cars);
        return cars;
    }


    /**
     * 修改车辆
     * @param cars
     * @return
     */
    @PutMapping("/{id}")
    public Cars updateCars(@RequestBody Cars cars){
        carsService.updateCar(cars);
        return cars;
    }

    /**
     * 删除车辆
     * @param groupId
     */
    @DeleteMapping("")
    public void deleteCars(@RequestBody List<String> groupId) {
        carsService.deleteCars(groupId);
    }


}
